﻿using Pay.Core;
using Pay.DTO;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace Pay.H5.Controllers {
    [AppAuthorize("Member")]
    public class OrderController : GeneralController {
        public OrderController() { }
        private IOrderService _orderService ;
        private ILogisticsDetailsService _logisticsDetailsService;
        private IPayInfoService _payInfoService;
        private IMerchantService _merchantService;

        public OrderController(IOrderService orderService,ILogisticsDetailsService logisticsDetailsService,
            IPayInfoService payInfoService,IMerchantService merchantService) {
            _orderService = orderService;
            _logisticsDetailsService = logisticsDetailsService;
            _payInfoService = payInfoService;
            _merchantService = merchantService;
        }
        /// <summary>
        /// 订单详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
		[AllowAnonymous]
        public ActionResult OrderDetail(long Id) {
            var model = _orderService.Get(Id);
            ViewData["url"] = site.img_url;
            ViewData["model"] = model;
            return View();
        }
        /// <summary>
        /// 隐藏身份证号码
        /// </summary>
        /// <returns>The ard hide.</returns>
        /// <param name="card">Card.</param>
        public static string IDCardHide(string card) {
            string temp = null;
            if (card.Length == 18) {
                temp = card.Substring(0, 5) + "***********" + card.Substring(16, 2);
            }
            if (card.Length == 15) {
                temp = card.Substring(0, 4) + "********" + card.Substring(12, 3);
            }
            return temp;
        }
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
		[AllowAnonymous]
        public JsonResult Cancel(long Id) {
            int result = _orderService.Delete(Id);
            if (result <= 0) {
                api_result.result_code = 500;
                api_result.result_msg = "操作失败";
            }
            return Json(ResultToJson.Json(api_result), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 确认收货
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public JsonResult Receipt(long Id) {
            var model = _orderService.Get(Id);
            var ordermodel = new order_model();
            ordermodel.order_no = model.order_no;
            api_result = _orderService.OrderReceipt(ordermodel);
            return Json(api_result, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 待付款
        /// </summary>
        /// <returns></returns>
        public ActionResult OrderStayPay() {
            return View();
        }
        /// <summary>
        /// 待付款
        /// </summary>
        /// <returns></returns>
        public  ActionResult OrderStayFinish() {
            return View();
        }
		/// <summary>
		/// 物流详情
		/// </summary>
		/// <returns>The detail.</returns>
		/// <param name="OrderId">Order identifier.</param>
        public  ActionResult LogisticsDetail(long OrderId) {
            var model = new order_dto();
            if (OrderId >0) {
                model = _orderService.Get(OrderId);
            }
            ViewData["payinfo"] = model;
            ViewData["List"] = _logisticsDetailsService.GetList(model);
            return View();
        }
        /// <summary>
        /// 待付款
        /// </summary>
        /// <returns></returns>
		[AllowAnonymous]
        public ActionResult OrderStayAll() {
            return View();
        }
		[AllowAnonymous]
        public PartialViewResult _OrderStayAll(OrderQuery query) {
            var queryorder = new OrderQuery();
            queryorder.order_status = query.order_status;
			if(UserId>0)
				queryorder.user_id = UserId;
            queryorder.size = 2;
            queryorder.page = query.page;
            var list = _orderService.Get(queryorder);
			ViewData["url"] = site.img_url;
            return PartialView(list);
        }
       
        /// <summary>
        /// 待收货
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public ActionResult OrderStayReceipt() {
            return View();
        }
        /// <summary>
        /// 待发货
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public ActionResult OrderStayDeliver() {
            return View();
        }
    }
}